<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>promise加载图片</title>
</head>
<body>
  <img src="" alt="" id="img1">
  <script>
    let url = 'https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3892521478,1695688217&fm=26&gp=0.jpg'
   function LoadImg(url) {
     return new Promise((resolve, reject) => {
        var img = document.getElementById('img1')
        
        img.onload = () => {
          resolve(img)
        }
        img.onerror = () => {
          reject(new Error('图片加载错误'+ url))
        }
        console.log(img)
        img.src = url
    })
    
   }
   LoadImg(url).then((img) => {
    console.log(img.width)
    return img
   })
   .then(img => console.log(img.height))
   .catch(img => console.log(img))
  </script>
</body>
</html>